﻿@using System.Web.Mvc.Html;
@using System.Web.WebPages.Html;
@using System.Web.Mvc;
@using DddCms.Models.UIComponent.Accordion;
@using System.Text.RegularExpressions;

@helper AccordionRender(AccordionViewModel viewmodel)
    {
    <div class="accordion" id="@viewmodel.ID">
    @foreach (var item in viewmodel.AccordionPannels)
    {
        string current = "";
        string heightPannel = "0px";

        if (item.IsOpen)
        {
            current = "accordion-current";
        }
         
		<div class="accordion-pannel @current">
            <div class="accordion-pannel-header">
                <div class="accordion-pannel-header-text">
                @if (item.Icon != null)
                {
                    @IconHelpers.Icon(item.Icon)
                }
                    <span class="accordion-item-text">@item.Title</span>
                </div>
                <div class="accordion-button">
                    <div class="accordion-button-hover"></div>
                </div>
            </div>
            @if (item.IsOpen)
            {
                heightPannel = viewmodel.Height + "px";
            }
              
            <div class="accordion-pannel-body" style="height:@heightPannel">
                @foreach (var itemPannel in item.AccordionItem)
                {
                    <div class="accordion-body-item">
                        @{
                        Regex attributeARegex = new Regex("(?<attributeA>.*>+)(?<valueA>.+[^</a>])");
                        Match values = attributeARegex.Match(itemPannel.ActionLink.ToString());
                        }
                        @(new HtmlString(@values.Groups["attributeA"].Value))
                            @if (itemPannel.IconClass != null)
                            {
                                @IconHelpers.Icon(itemPannel.IconClass)
                            }
                                    
                            <span class="accordion-item-text">@values.Groups["valueA"].Value</span>
                        @(new HtmlString("</a>"))
                    </div>
                   
                }
            </div>
        </div>
    }
    </div>
}